import 'package:flutter/material.dart';
import 'home.dart';
import 'contact.dart';
import 'find.dart';
import 'mine.dart';

void main() {
  runApp(new MaterialApp(
    theme: new ThemeData(primaryColor: Colors.black),
    home: new WeChatApp(),
  ));
}

class WeChatApp extends StatefulWidget {
  @override
  WeChatAppState createState() {
    return new WeChatAppState();
  }
}

class WeChatAppState extends State<WeChatApp> {
  ///////////////////////////////////////////////
  int _tabIndex = 0;
  Color getItemColor(int index) {
    if (index == _tabIndex) {
      return Colors.green;
    } else {
      return Colors.grey;
    }
  }

  List<BottomNavigationBarItem> getBottomNavigationBarItems() {
    List<BottomNavigationBarItem> list = [
      new BottomNavigationBarItem(
          icon: new Icon(
            Icons.chat,
            color: getItemColor(0),
          ),
          title: new Text(
            "微信",
            style: new TextStyle(color: getItemColor(0)),
          )),
      new BottomNavigationBarItem(
          icon: new Icon(
            Icons.perm_contact_calendar,
            color: getItemColor(1),
          ),
          title: new Text(
            "通讯录",
            style: new TextStyle(color: getItemColor(1)),
          )),
      new BottomNavigationBarItem(
          icon: new Icon(
            Icons.room,
            color: getItemColor(2),
          ),
          title: new Text(
            "发现",
            style: new TextStyle(color: getItemColor(2)),
          )),
      new BottomNavigationBarItem(
          icon: new Icon(
            Icons.perm_identity,
            color: getItemColor(3),
          ),
          title: new Text(
            "我",
            style: new TextStyle(color: getItemColor(3)),
          ))
    ];
    return list;
  }

  final List<BottomNavigationBarItem> list = [];

  final List<StatefulWidget> _pages = [
    new HomePage(),
    new ContactPage(),
    new FindPage(),
    new MinePage(),
  ];
  /////////////////////////////////////////////////
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("微信"),
        actions: <Widget>[
          new IconButton(
            icon: new Icon(
              Icons.search,
              color: Colors.white,
            ),
            onPressed: () {},
          ),
          new IconButton(
            icon: new Icon(
              Icons.add,
              color: Colors.white,
            ),
            onPressed: () {},
          ),
        ],
      ),
      body: _pages[_tabIndex],
      bottomNavigationBar: new BottomNavigationBar(
        items: getBottomNavigationBarItems(),
        type: BottomNavigationBarType.fixed,
        onTap: (int index) {
          setState(() {
            _tabIndex = index;
          });
          print("BottomNavigationBar Click Index $index");
        },
      ),
    );
  }
}
